package com.yotoodesign.dianba.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.util.Log;

import com.yotoodesign.dianba.bean.Adv;
import com.yotoodesign.dianba.bean.BaseData;
import com.yotoodesign.dianba.bean.Singer;
import com.yotoodesign.dianba.bean.Song;
import com.yotoodesign.dianba.bean.Tag;

public class DataUtils {
	
	/*
	 * 根据拼音从列表中过滤数据
	 */
	public static  ArrayList<BaseData> filterHandler(ArrayList<BaseData> list,String pinyin){
		ArrayList<BaseData> result = new ArrayList<BaseData>();
		for(int i = 0;i<list.size();i++){
			BaseData data = (BaseData)list.get(i);
			if(data.getPinyin().toUpperCase().startsWith(pinyin.toUpperCase())){
				result.add(data);
			}
		}
		return result;
	}

	/*
	 * TOP10 Songs
	 */
	public static ArrayList<BaseData> loadTop10Songs(){
		ArrayList<BaseData> top10songs = new ArrayList<BaseData>();
//		Top10SongService.getInstance().prepare("/top10songs.xml");
		List songs = Top10SongService.getInstance().first();
		
		
		for(Iterator<Song> it = songs.iterator();it.hasNext();){
			Song song = it.next();
			Singer singer = SingerService.getInstance().findSinger(song.getSinger().getId());
			song.setSinger(singer);
			top10songs.add(song);
		}
		return top10songs;
	}
	
	/*
	 * Top10 singers
	 */
	public static ArrayList<BaseData> loadTop10Singers(){
		ArrayList<BaseData> top10singers = new ArrayList<BaseData>();
		
//		Top10SingerService.getInstance().prepare("/top10singers.xml");
		List singers = Top10SingerService.getInstance().first();
		for(Iterator<Singer> it = singers.iterator();it.hasNext();){
			top10singers.add(it.next());
		}
		
		return top10singers;
	}
	
	/*
	 * 歌手列表
	 */
	public static ArrayList<BaseData> loadSingers(){
		ArrayList<BaseData> singerList = new ArrayList<BaseData>();
//		SingerService.getInstance().prepare("/singers.xml");
		List singers = SingerService.getInstance().first();
		for(Iterator<Singer> it = singers.iterator();it.hasNext();){
			singerList.add(it.next());
		}
		return singerList;
	}
	
	/*
	 * 歌曲列表
	 */
	public static ArrayList<BaseData> loadSingerSongs(Singer singer){
		ArrayList<BaseData> songList = new ArrayList<BaseData>();
		
		List list = SongService.getInstance().findSingerSongs(singer.getId());
		SongService.getInstance().init(list, Pager.DEFAULT_PAGE_SIZE);
		
		List songs = SongService.getInstance().first();
		for(Iterator<Song> it = songs.iterator();it.hasNext();){
			Song song = it.next();
			song.setSinger(singer);
			songList.add(song);
		}
		return songList;
	}
	
	/*
	 * 广告 数据
	 */
	public static ArrayList<BaseData> loadAdvs(){
		ArrayList<BaseData> advs = new ArrayList<BaseData>();
		advs.add(new Adv("集结号周年活动"));
		advs.add(new Adv("阿里巴巴量贩城国庆大酬宾"));
		advs.add(new Adv("方糖量贩KTV团购"));
		advs.add(new Adv("钱柜KTV贵宾卡"));
		advs.add(new Adv("阿波罗视听歌城"));
		return advs;
	}
	
	/*
	 * 我的标签
	 */
	public static ArrayList<Tag> loadMyTags(){
		ArrayList<Tag> tags = new ArrayList<Tag>();
		tags.add(new Tag("70后"));
		tags.add(new Tag("校园民谣"));
		tags.add(new Tag("摇滚"));
		tags.add(new Tag("张学友"));
		tags.add(new Tag("中国好声音"));
		return tags;
	}
}
